package com.kusen.village.raise.util;

import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Hopeful
 */
@ApiModel
public class PageList<T> {
	@ApiModelProperty(value="当前页")
	private Integer pageIndex;
	@ApiModelProperty(value="每页条数")
	private Integer pageSize;
	@ApiModelProperty(value="每页数据")
	private List<T> rows = new ArrayList<T>();
	@ApiModelProperty(hidden=true)
	private Integer startRow;
	@ApiModelProperty(hidden=true)
	private Integer endRow;
	@ApiModelProperty(value="总条数")
	private Long total;
	@ApiModelProperty(value="其他计数")
	private Long otherNum;//其他计数
	@ApiModelProperty(hidden=true)
	@JSONField(serialize=false)
	private T filter;


	public T getFilter() {
		return filter;
	}
	public void setFilter(T filter) {
		this.filter = filter;
	}
	public Long getTotal() {
		return total;
	}
	public void setTotal(Long total) {
		this.total = total;
	}
	public PageList() {
	}
	public PageList(Integer pageIndex, Integer pageSize) {
		super();
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;
	}
	public Integer getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(Integer pageIndex) {
		this.pageIndex = pageIndex;
	}
	 public List<T> getRows() {
		return rows;
	}
	public void setRows(List<T> rows) {
		this.rows = rows;
	}
	public Integer getPageSize() {
		return pageSize==null?10:pageSize;
	}
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	public Long getOtherNum() {
		return otherNum;
	}
	public void setOtherNum(Long otherNum) {
		this.otherNum = otherNum;
	}
	/*  
     * 获得开始行数  
     */    
    public Integer getStartRow() {    
    	if (pageIndex!=null&&pageIndex!=0) {
    		 return (pageIndex - 1) * pageSize;    
		}else {
			return 0;
		}
       

    }    
    /*  
     * 获得结束行  
     */    
    public Integer getEndRow() {    
    	if (pageIndex!=null&&pageIndex!=0) {
    		 return pageIndex * pageSize;    
		}else {
			return 0;
		}
    } 
    public void setStartRow(Integer startRow) {
		this.startRow = startRow;
	}
	public void setEndRow(Integer endRow) {
		this.endRow = endRow;
	}
}
